How can I optimize Apache to use 1GB of RAM on my website? [closed]

Posted by Markon on Pro Webmasters See other posts from Pro Webmasters or by Markon
Published on 2011-02-06T17:49:28Z Indexed on 2011/02/06 23:35 UTC
Read the original article Hit count: 267

Filed under:
|
|

My VPS plan gives me 1GB of RAM burstable to 2GB. Of course I cannot use 2 GB, nor > 1 GB, everyday, so I'm planning to optimize the performance of my webserver.

The average of hits-per-hour is about 8'000-10'000. This means about 2 connections-per-second. Max hits-per-hour reached until now is about 60'000. That means about 16 connections-per-second.

Unluckily my current apache configuration uses too much memory (when there are not connected clients - usually during the night - it uses about 1GB) so I've tried to customize the apache installation to fit to my needs.

I'm using Ubuntu, kernel 2.6.18, with apache2-mpm-worker, since I've read it requires less memory, and fcgid ( + PHP). This is my /etc/apache2/apache2.conf:

Timeout 45
KeepAlive on
MaxKeepAliveRequests 100
KeepAliveTimeout 10
<IfModule mpm_worker_module>
    StartServer 2
    MinSpareThreads 25
    MaxSpareThreads 75
    MaxClients 100
    MaxRequestsPerChild 0
</IfModule>

This is the output of ps aux:

www-data  9547  0.0  0.3 423828  7268 ?        Sl   20:09   0:00 /usr/sbin/apache2 -k start
root     17714  0.0  0.1  76496  3712 ?        Ss   Feb05   0:00 /usr/sbin/apache2 -k start
www-data 17716  0.0  0.0  75560  2048 ?        S    Feb05   0:00 /usr/sbin/apache2 -k start
www-data 17746  0.0  0.1  76228  2384 ?        S    Feb05   0:00 /usr/sbin/apache2 -k start
www-data 20126  0.0  0.3 424852  7588 ?        Sl   19:24   0:02 /usr/sbin/apache2 -k start
www-data 24260  0.0  0.3 424852  7580 ?        Sl   19:42   0:01 /usr/sbin/apache2 -k start

while this is ps aux for php5:

www-data  7461  2.9  2.2 142172 47048 ?        S    19:39   1:39 /usr/lib/cgi-bin/php5
www-data 23845  1.3  1.7 135744 35948 ?        S    20:17   0:15 /usr/lib/cgi-bin/php5
www-data 23900  2.0  1.7 136692 36760 ?        S    20:17   0:22 /usr/lib/cgi-bin/php5
www-data 27907  2.0  2.0 142272 43432 ?        S    20:00   0:43 /usr/lib/cgi-bin/php5
www-data 27909  2.5  1.9 138092 40036 ?        S    20:00   0:53 /usr/lib/cgi-bin/php5
www-data 27993  2.4  2.2 142336 47192 ?        S    20:01   0:50 /usr/lib/cgi-bin/php5
www-data 27999  1.8  1.4 135932 31100 ?        S    20:01   0:38 /usr/lib/cgi-bin/php5
www-data 28230  2.6  1.9 143436 39956 ?        S    20:01   0:54 /usr/lib/cgi-bin/php5
www-data 30708  3.1  2.2 142508 46528 ?        S    19:44   1:38 /usr/lib/cgi-bin/php5

As you can see it use a lot of memory. How can I reduce it to fit to just 1GB of RAM?

PS: I also think about the switch to nginx, if Apache can't fit to my needs...

© Pro Webmasters or respective owner

Related posts about apache

Related posts about optimizations